package com.collectionAndMap.collection.list;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

/***
 * @ClassName: ListDemo
 * @Description:
 * @Auther: 送一一块二向箔
 * @Date: 15:22 2022/2/15
 * @version : V1.0
 */
public class ListDemo {

    public static void main(String[] args) {
        test1();
    }


    public static void test1(){
        List arrayList = new ArrayList();
        arrayList.add("菠萝");
        arrayList.add("西瓜");
        arrayList.add("香蕉");

        //listIterator可以任意方向遍历，可以添加，修改，删除元素
        ListIterator listIterator = arrayList.listIterator();
        while (listIterator.hasNext()) {
            System.out.println(listIterator.next());
        }
        while (listIterator.hasPrevious()) {
            System.out.println(listIterator.previous());
        }
    }


    public static void test2(){
        List arrayList = new ArrayList();
        arrayList.add("菠萝");
        arrayList.add("西瓜");
        arrayList.add("香蕉");

        //listIterator可以任意方向遍历，可以添加，修改，删除元素
        ListIterator listIterator = arrayList.listIterator();
        while (listIterator.hasNext()) {
            System.out.println(listIterator.next());
        }
        while (listIterator.hasPrevious()) {
            System.out.println(listIterator.previous());
        }
    }
}
